package lan.core.message

import lan.core.file._

trait Query extends java.io.Serializable {
  def matches(f: FileRepresentation): Boolean
}

final case class Conjunction(val queries: Iterable[Query]) extends Query {
  def matches(f: FileRepresentation) = queries.forall( _.matches(f))
}

final case class Disjunction(val queries: Iterable[Query]) extends Query {
  def matches(f: FileRepresentation) = queries.exists(_.matches(f))
}

final case class SuffixMatch(val suffix: String) extends Query {
  def matches(f: FileRepresentation) = f.name.endsWith(suffix)
}

final case class AnyKeywordMatch(val keys: Iterable[String]) extends Query {
    def matches(f: FileRepresentation) = keys.exists(f.keywords.contains(_))
}

final case class PartialNameMatch(val name: String) extends Query {
  def matches(f: FileRepresentation) = f.name.contains(name.toLowerCase)
}